package com.ITArmy.controller.admin;

import com.ITArmy.beans.Type;
import com.ITArmy.common.ServerResponse;
import com.ITArmy.controller.base.BaseController;
import com.ITArmy.service.TypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Api(value = "后台博客类型接口层次", tags = "后台博客类型接口层次Controller层")
@Controller
@RequestMapping("/admin/Type")
public class AdminTypeController extends BaseController {

    @RequestMapping("/list")
    @ApiOperation(value = "显示所有类型信息",
            httpMethod = "POST", response = ServerResponse.class)
    public String list(Model model){
        ServerResponse typeServerResponse=typeService.typeList();
        model.addAttribute("typeList",typeServerResponse.getData());
        return "type";
    }

    @RequestMapping("/add")
    @ResponseBody
    @ApiOperation(value = "添加类型信息",
            httpMethod = "POST", response = ServerResponse.class)
    public ServerResponse addType(Type type){
        return typeService.addType(type);
    }

    @RequestMapping("/delete")
    @ResponseBody
    @ApiOperation(value = "删除类型信息",
            httpMethod = "DELETE", response = ServerResponse.class)
    public ServerResponse delete(Long id){
        return typeService.deleteType(id);
    }

    @RequestMapping("/deleteMany")
    @ResponseBody
    @ApiOperation(value = "批量删除类型信息",
            httpMethod = "DELETE", response = ServerResponse.class)
    public ServerResponse deleteMany(String ids){
        String[] id=ids.split(",");
        return typeService.deleteManyByIds(id);
    }

    @RequestMapping("/update")
    @ResponseBody
    @ApiOperation(value = "修改类型信息",
            httpMethod = "POST", response = ServerResponse.class)
    public ServerResponse update(Type type){
        return typeService.updateType(type);
    }

    @RequestMapping("/select")
    @ResponseBody
    @ApiOperation(value = "搜索类型信息",notes = "暂时先不用此功能",
            httpMethod = "POST", response = ServerResponse.class)
    public ServerResponse select(String name){
        return typeService.findTypeByNameLike(name);
    }
}
